{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#Series (collection of values)\n",
    "#DataFrame (collection of Series objects)\n",
    "#Panel (collection of DataFrame objects)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "#A Series object can hold many data types, including\n",
    "#float - for representing float values\n",
    "#int - for representing integer values\n",
    "#bool - for representing Boolean values\n",
    "#datetime64[ns] - for representing date & time, without time-zone\n",
    "#datetime64[ns, tz] - for representing date & time, with time-zone\n",
    "#timedelta[ns] - for representing differences in dates & times (seconds, minutes, etc.)\n",
    "#category - for representing categorical values\n",
    "#object - for representing String values\n",
    "\n",
    "#FILM - film name\n",
    "#RottenTomatoes - Rotten Tomatoes critics average score\n",
    "#RottenTomatoes_User - Rotten Tomatoes user average score\n",
    "#RT_norm - Rotten Tomatoes critics average score (normalized to a 0 to 5 point system)\n",
    "#RT_user_norm - Rotten Tomatoes user average score (normalized to a 0 to 5 point system)\n",
    "#Metacritic - Metacritic critics average score\n",
    "#Metacritic_User - Metacritic user average score"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0    Avengers: Age of Ultron (2015)\n",
      "1                 Cinderella (2015)\n",
      "2                    Ant-Man (2015)\n",
      "3            Do You Believe? (2015)\n",
      "4     Hot Tub Time Machine 2 (2015)\n",
      "Name: FILM, dtype: object\n",
      "0    74\n",
      "1    85\n",
      "2    80\n",
      "3    18\n",
      "4    14\n",
      "Name: RottenTomatoes, dtype: int64\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "fandango = pd.read_csv('fandango_score_comparison.csv')\n",
    "series_film = fandango['FILM']\n",
    "print(series_film[0:5])\n",
    "series_rt = fandango['RottenTomatoes']\n",
    "print (series_rt[0:5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Minions (2015)      54\n",
       "Leviathan (2014)    99\n",
       "dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# Import the Series object from pandas\n",
    "from pandas import Series\n",
    "\n",
    "film_names = series_film.values\n",
    "#print type(film_names)\n",
    "#print film_names\n",
    "rt_scores = series_rt.values\n",
    "#print rt_scores\n",
    "series_custom = Series(rt_scores , index=film_names)\n",
    "series_custom[['Minions (2015)', 'Leviathan (2014)']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "The Water Diviner (2015)        63\n",
      "Irrational Man (2015)           42\n",
      "Top Five (2014)                 86\n",
      "Shaun the Sheep Movie (2015)    99\n",
      "Love & Mercy (2015)             89\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "# int index is also aviable\n",
    "series_custom = Series(rt_scores , index=film_names)\n",
    "series_custom[['Minions (2015)', 'Leviathan (2014)']]\n",
    "fiveten = series_custom[5:10]\n",
    "print(fiveten)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "'71 (2015)                                         97\n",
      "5 Flights Up (2015)                                52\n",
      "A Little Chaos (2015)                              40\n",
      "A Most Violent Year (2014)                         90\n",
      "About Elly (2015)                                  97\n",
      "Aloha (2015)                                       19\n",
      "American Sniper (2015)                             72\n",
      "American Ultra (2015)                              46\n",
      "Amy (2015)                                         97\n",
      "Annie (2014)                                       27\n",
      "Ant-Man (2015)                                     80\n",
      "Avengers: Age of Ultron (2015)                     74\n",
      "Big Eyes (2014)                                    72\n",
      "Birdman (2014)                                     92\n",
      "Black Sea (2015)                                   82\n",
      "Black or White (2015)                              39\n",
      "Blackhat (2015)                                    34\n",
      "Cake (2015)                                        49\n",
      "Chappie (2015)                                     30\n",
      "Child 44 (2015)                                    26\n",
      "Cinderella (2015)                                  85\n",
      "Clouds of Sils Maria (2015)                        89\n",
      "Danny Collins (2015)                               77\n",
      "Dark Places (2015)                                 26\n",
      "Do You Believe? (2015)                             18\n",
      "Dope (2015)                                        87\n",
      "Entourage (2015)                                   32\n",
      "Escobar: Paradise Lost (2015)                      52\n",
      "Ex Machina (2015)                                  92\n",
      "Fantastic Four (2015)                               9\n",
      "                                                   ..\n",
      "The Loft (2015)                                    11\n",
      "The Longest Ride (2015)                            31\n",
      "The Man From U.N.C.L.E. (2015)                     68\n",
      "The Overnight (2015)                               82\n",
      "The Salt of the Earth (2015)                       96\n",
      "The Second Best Exotic Marigold Hotel (2015)       62\n",
      "The SpongeBob Movie: Sponge Out of Water (2015)    78\n",
      "The Stanford Prison Experiment (2015)              84\n",
      "The Vatican Tapes (2015)                           13\n",
      "The Water Diviner (2015)                           63\n",
      "The Wedding Ringer (2015)                          27\n",
      "The Wolfpack (2015)                                84\n",
      "The Woman In Black 2 Angel of Death (2015)         22\n",
      "The Wrecking Crew (2015)                           93\n",
      "Timbuktu (2015)                                    99\n",
      "Tomorrowland (2015)                                50\n",
      "Top Five (2014)                                    86\n",
      "Trainwreck (2015)                                  85\n",
      "True Story (2015)                                  45\n",
      "Two Days, One Night (2014)                         97\n",
      "Unbroken (2014)                                    51\n",
      "Unfinished Business (2015)                         11\n",
      "Unfriended (2015)                                  60\n",
      "Vacation (2015)                                    27\n",
      "Welcome to Me (2015)                               71\n",
      "What We Do in the Shadows (2015)                   96\n",
      "When Marnie Was There (2015)                       89\n",
      "While We're Young (2015)                           83\n",
      "Wild Tales (2014)                                  96\n",
      "Woman in Gold (2015)                               52\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "original_index = series_custom.index.tolist()\n",
    "#print original_index\n",
    "sorted_index = sorted(original_index)\n",
    "sorted_by_index = series_custom.reindex(sorted_index)\n",
    "#print sorted_by_index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Paul Blart: Mall Cop 2 (2015)     5\n",
      "Hitman: Agent 47 (2015)           7\n",
      "Hot Pursuit (2015)                8\n",
      "Fantastic Four (2015)             9\n",
      "Taken 3 (2015)                    9\n",
      "The Boy Next Door (2015)         10\n",
      "The Loft (2015)                  11\n",
      "Unfinished Business (2015)       11\n",
      "Mortdecai (2015)                 12\n",
      "Seventh Son (2015)               12\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "sc2 = series_custom.sort_index()\n",
    "sc3 = series_custom.sort_values()\n",
    "#print(sc2[0:10])\n",
    "print(sc3[0:10])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Avengers: Age of Ultron (2015)                    148\n",
      "Cinderella (2015)                                 170\n",
      "Ant-Man (2015)                                    160\n",
      "Do You Believe? (2015)                             36\n",
      "Hot Tub Time Machine 2 (2015)                      28\n",
      "The Water Diviner (2015)                          126\n",
      "Irrational Man (2015)                              84\n",
      "Top Five (2014)                                   172\n",
      "Shaun the Sheep Movie (2015)                      198\n",
      "Love & Mercy (2015)                               178\n",
      "Far From The Madding Crowd (2015)                 168\n",
      "Black Sea (2015)                                  164\n",
      "Leviathan (2014)                                  198\n",
      "Unbroken (2014)                                   102\n",
      "The Imitation Game (2014)                         180\n",
      "Taken 3 (2015)                                     18\n",
      "Ted 2 (2015)                                       92\n",
      "Southpaw (2015)                                   118\n",
      "Night at the Museum: Secret of the Tomb (2014)    100\n",
      "Pixels (2015)                                      34\n",
      "McFarland, USA (2015)                             158\n",
      "Insidious: Chapter 3 (2015)                       118\n",
      "The Man From U.N.C.L.E. (2015)                    136\n",
      "Run All Night (2015)                              120\n",
      "Trainwreck (2015)                                 170\n",
      "Selma (2014)                                      198\n",
      "Ex Machina (2015)                                 184\n",
      "Still Alice (2015)                                176\n",
      "Wild Tales (2014)                                 192\n",
      "The End of the Tour (2015)                        184\n",
      "                                                 ... \n",
      "Clouds of Sils Maria (2015)                       178\n",
      "Testament of Youth (2015)                         162\n",
      "Infinitely Polar Bear (2015)                      160\n",
      "Phoenix (2015)                                    198\n",
      "The Wolfpack (2015)                               168\n",
      "The Stanford Prison Experiment (2015)             168\n",
      "Tangerine (2015)                                  190\n",
      "Magic Mike XXL (2015)                             124\n",
      "Home (2015)                                        90\n",
      "The Wedding Ringer (2015)                          54\n",
      "Woman in Gold (2015)                              104\n",
      "The Last Five Years (2015)                        120\n",
      "Mission: Impossible â€“ Rogue Nation (2015)       184\n",
      "Amy (2015)                                        194\n",
      "Jurassic World (2015)                             142\n",
      "Minions (2015)                                    108\n",
      "Max (2015)                                         70\n",
      "Paul Blart: Mall Cop 2 (2015)                      10\n",
      "The Longest Ride (2015)                            62\n",
      "The Lazarus Effect (2015)                          28\n",
      "The Woman In Black 2 Angel of Death (2015)         44\n",
      "Danny Collins (2015)                              154\n",
      "Spare Parts (2015)                                104\n",
      "Serena (2015)                                      36\n",
      "Inside Out (2015)                                 196\n",
      "Mr. Holmes (2015)                                 174\n",
      "'71 (2015)                                        194\n",
      "Two Days, One Night (2014)                        194\n",
      "Gett: The Trial of Viviane Amsalem (2015)         200\n",
      "Kumiko, The Treasure Hunter (2015)                174\n",
      "dtype: int64\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "100"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#The values in a Series object are treated as an ndarray, the core data type in NumPy\n",
    "import numpy as np\n",
    "# Add each value with each other\n",
    "print np.add(series_custom, series_custom)\n",
    "# Apply sine function to each value\n",
    "np.sin(series_custom)\n",
    "# Return the highest value (will return a single value not a Series)\n",
    "np.max(series_custom)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Avengers: Age of Ultron (2015)                                            74\n",
      "The Water Diviner (2015)                                                  63\n",
      "Unbroken (2014)                                                           51\n",
      "Southpaw (2015)                                                           59\n",
      "Insidious: Chapter 3 (2015)                                               59\n",
      "The Man From U.N.C.L.E. (2015)                                            68\n",
      "Run All Night (2015)                                                      60\n",
      "5 Flights Up (2015)                                                       52\n",
      "Welcome to Me (2015)                                                      71\n",
      "Saint Laurent (2015)                                                      51\n",
      "Maps to the Stars (2015)                                                  60\n",
      "Pitch Perfect 2 (2015)                                                    67\n",
      "The Age of Adaline (2015)                                                 54\n",
      "The DUFF (2015)                                                           71\n",
      "Ricki and the Flash (2015)                                                64\n",
      "Unfriended (2015)                                                         60\n",
      "American Sniper (2015)                                                    72\n",
      "The Hobbit: The Battle of the Five Armies (2014)                          61\n",
      "Paper Towns (2015)                                                        55\n",
      "Big Eyes (2014)                                                           72\n",
      "Maggie (2015)                                                             54\n",
      "Focus (2015)                                                              57\n",
      "The Second Best Exotic Marigold Hotel (2015)                              62\n",
      "The 100-Year-Old Man Who Climbed Out the Window and Disappeared (2015)    67\n",
      "Escobar: Paradise Lost (2015)                                             52\n",
      "Into the Woods (2014)                                                     71\n",
      "Inherent Vice (2014)                                                      73\n",
      "Magic Mike XXL (2015)                                                     62\n",
      "Woman in Gold (2015)                                                      52\n",
      "The Last Five Years (2015)                                                60\n",
      "Jurassic World (2015)                                                     71\n",
      "Minions (2015)                                                            54\n",
      "Spare Parts (2015)                                                        52\n",
      "dtype: int64\n"
     ]
    }
   ],
   "source": [
    "#will actually return a Series object with a boolean value for each film\n",
    "series_custom > 50\n",
    "series_greater_than_50 = series_custom[series_custom > 50]\n",
    "\n",
    "criteria_one = series_custom > 50\n",
    "criteria_two = series_custom < 75\n",
    "both_criteria = series_custom[criteria_one & criteria_two]\n",
    "print both_criteria"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {
    "collapsed": false
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "FILM\n",
      "Avengers: Age of Ultron (2015)                    80.0\n",
      "Cinderella (2015)                                 82.5\n",
      "Ant-Man (2015)                                    85.0\n",
      "Do You Believe? (2015)                            51.0\n",
      "Hot Tub Time Machine 2 (2015)                     21.0\n",
      "The Water Diviner (2015)                          62.5\n",
      "Irrational Man (2015)                             47.5\n",
      "Top Five (2014)                                   75.0\n",
      "Shaun the Sheep Movie (2015)                      90.5\n",
      "Love & Mercy (2015)                               88.0\n",
      "Far From The Madding Crowd (2015)                 80.5\n",
      "Black Sea (2015)                                  71.0\n",
      "Leviathan (2014)                                  89.0\n",
      "Unbroken (2014)                                   60.5\n",
      "The Imitation Game (2014)                         91.0\n",
      "Taken 3 (2015)                                    27.5\n",
      "Ted 2 (2015)                                      52.0\n",
      "Southpaw (2015)                                   69.5\n",
      "Night at the Museum: Secret of the Tomb (2014)    54.0\n",
      "Pixels (2015)                                     35.5\n",
      "McFarland, USA (2015)                             84.0\n",
      "Insidious: Chapter 3 (2015)                       57.5\n",
      "The Man From U.N.C.L.E. (2015)                    74.0\n",
      "Run All Night (2015)                              59.5\n",
      "Trainwreck (2015)                                 79.5\n",
      "Selma (2014)                                      92.5\n",
      "Ex Machina (2015)                                 89.0\n",
      "Still Alice (2015)                                86.5\n",
      "Wild Tales (2014)                                 94.0\n",
      "The End of the Tour (2015)                        90.5\n",
      "                                                  ... \n",
      "Clouds of Sils Maria (2015)                       78.0\n",
      "Testament of Youth (2015)                         80.0\n",
      "Infinitely Polar Bear (2015)                      78.0\n",
      "Phoenix (2015)                                    90.0\n",
      "The Wolfpack (2015)                               78.5\n",
      "The Stanford Prison Experiment (2015)             85.5\n",
      "Tangerine (2015)                                  90.5\n",
      "Magic Mike XXL (2015)                             63.0\n",
      "Home (2015)                                       55.0\n",
      "The Wedding Ringer (2015)                         46.5\n",
      "Woman in Gold (2015)                              66.5\n",
      "The Last Five Years (2015)                        60.0\n",
      "Mission: Impossible â€“ Rogue Nation (2015)       91.0\n",
      "Amy (2015)                                        94.0\n",
      "Jurassic World (2015)                             76.0\n",
      "Minions (2015)                                    53.0\n",
      "Max (2015)                                        54.0\n",
      "Paul Blart: Mall Cop 2 (2015)                     20.5\n",
      "The Longest Ride (2015)                           52.0\n",
      "The Lazarus Effect (2015)                         18.5\n",
      "The Woman In Black 2 Angel of Death (2015)        23.5\n",
      "Danny Collins (2015)                              76.0\n",
      "Spare Parts (2015)                                67.5\n",
      "Serena (2015)                                     21.5\n",
      "Inside Out (2015)                                 94.0\n",
      "Mr. Holmes (2015)                                 82.5\n",
      "'71 (2015)                                        89.5\n",
      "Two Days, One Night (2014)                        87.5\n",
      "Gett: The Trial of Viviane Amsalem (2015)         90.5\n",
      "Kumiko, The Treasure Hunter (2015)                75.0\n",
      "dtype: float64\n"
     ]
    }
   ],
   "source": [
    "#data alignment same index\n",
    "rt_critics = Series(fandango['RottenTomatoes'].values, index=fandango['FILM'])\n",
    "rt_users = Series(fandango['RottenTomatoes_User'].values, index=fandango['FILM'])\n",
    "rt_mean = (rt_critics + rt_users)/2\n",
    "\n",
    "print(rt_mean)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 2",
   "language": "python",
   "name": "python2"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
